home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------------------------------------------
- *
- * Simple Sample PowerTalk Application Framework
- *
- * ©1991-1993 Apple Computer
- *
- -------------------------------------------------------------------------------------*/
- /*
- * main.c -- main entry point and initialization
- *
- * change history:
- *
- * SJF 08/23/93 1.0f1 update to final headers, fix comments
- * SJF 04/21/93 1.0b2 update to b2
- * SJF 03/01/93 1.0b1 added digital signatures
- * SJF 02/09/93 1.0b1 update to b1
- * SJF 10/13/92 1.0d4 update to a11
- * SJF 09/09/92 1.0d3 update to a9
- * SJF 05/07/92 1.0d2 update to a6
- * SJF 11/06/91 1.0d1 initial coding
- *
- */
-
- #ifndef __TRAPS__
- #include <Traps.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __TEXTEDIT__
- #include <TextEdit.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __OSEVENTS__
- #include <OSEvents.h>
- #endif
-
- #include "const.h"
- #include "mytypes.h"
- #include "mymenus.h"
- #include "globals.h"
- #include "utils.h"
- #include "trapavailable.h"
- #include "myevents.h"
- #include "mystandardmail.h"
- #include "aevt.h"
- #include "digisig.h"
-
- #include "main.h"
-
- /* main entry point */
-
- void main(void)
- {
- OSErr err;
-
- err = InitToolboxes(); // init the mac toolbox
- if (err!=noErr)
- ExitToShell();
-
- err = InitApplication(); // init our application specific stuff
- if (err!=noErr)
- ExitToShell();
-
- if (gHasStandardMail) { // init aoce standard mail if available
- err = InitStandardMail();
- if (err!=noErr)
- ExitToShell();
- }
-
- if (gHasDigiSign) { // init digital signatures if available
- err = InitDigitalSignatures();
- if (err!=noErr)
- ExitToShell();
- }
-
- // lets go!
-
- do {
- MainLoop();
- } while (!ExitProgram());
-
- if (gHasDigiSign) // clean up after the digital signatures
- ExitDigitalSignatures();
- WritePrefs(); // write our prefs to disk
-
- ExitToShell();
- }
-
-
- /* initializes the standard Mac toolbox */
-
- OSErr InitToolboxes(void)
- {
- OSErr err;
-
- MaxApplZone();
- MoreMasters();
- MoreMasters();
- MoreMasters();
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
- FlushEvents(everyEvent,0L);
-
- if (SupportsAEVT()) {
- RegisterMyEvents();
- }
-
- PrOpen();
- err = PrError();
- PrClose();
-
- if (PrError()!=noErr)
- StopAlert(kNoPrinterAlertID,nil);
-
- return err;
- }
-
-
- /* initializes the application globals/menus/windows/etc... */
-
- OSErr InitApplication(void)
- {
- CursHandle cursH;
-
- // global variable initialization
-
- gHasWaitNextEvent = TrapAvailable(_WaitNextEvent);
- gHasStandardMail = HasStandardMail();
- gHasDigiSign = HasDigiSign();
-
- gDone = false;
- gInBackground = false;
- gMenusDirty = false;
- gHasCopyWindow = false;
-
- cursH = GetCursor(kPencilCursorID);
- gPencilCursor = **cursH;
- cursH = GetCursor(watchCursor);
- gWatchCursor = **cursH;
-
- gNextWindowToMake = 1;
-
- ReadPrefs();
- InitMyMenus();
- InitMyWindows();
-
- ClearAppUndo();
-
- return noErr;
- }
-
-
- /* sets up the menu bar */
-
- void InitMyMenus(void)
- {
- MenuHandle theMenu;
- Handle mbarHandle;
-
- mbarHandle = GetNewMBar(kMenuBar);
- SetMenuBar(mbarHandle);
-
- theMenu = GetMHandle(kAppleMenu);
- AddResMenu(theMenu,'DRVR'); // build apple menu
-
- SetDefaultMenus();
-
- theMenu = GetMHandle(kShapesMenu);
- CheckItem(theMenu,kLineShape,true);
- gCurrentShape = kLineShape;
-
- gMenusDirty = true;
- }
-
-
- /* displays any initial windows */
-
- void InitMyWindows(void)
- {
- }
-